<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <a href="" class="buy" id="one">12</a>
    <a href="" class="buy">12</a>
    <a href="" class="buy">12</a>
    <a href="" class="buy">12</a>
    <a href="" class="buy">12</a>
</body> 
<script>
   
console.log(parseInt(document.getElementById('one').innerText));

    var all=document.querySelectorAll('.buy');
    console.log(all);
    var id=0;
    for(var i=0;i<all.length;i++){
    id=id+ parseInt(all[i].innerText);   
    console.log(id);
    
    }
    console.log(id);
    
    
   
    
    
    
</script>
</html>